//
// Created by Leaf on 2025/8/17.
//

#include "my_rtosConfig.h"
#include <freertos/timers.h>
#include "global/GData.h"
#include "global/GObject.h"

// 定时器ID定义
#define HEARTBEAT_TIMER_ID 1

uint32_t timeCount = 0;


// 定时器回调函数声明
void buttonTimerCallback(TimerHandle_t xTimer){
    if(button0.isPressed()){
        if(timeCount >= MODE_SWITCH_TIME_S){
            timeCount = 0;
            nowRunMode = !nowRunMode;   // 模式切换
            printf("nowMode: %d\n", nowRunMode);
        }else{
            timeCount ++  ;
        }
    }
}


// 定时器初始化
void Timer_init(){
    // 定时器句柄 (参数：定时器名称，定时时间，自动重载，定时器ID，定时器回调函数)
    TimerHandle_t xHeartbeatTimer = xTimerCreate(
            "buttonTimer",
            pdMS_TO_TICKS(1000),
            pdTRUE,
            (void *) HEARTBEAT_TIMER_ID,
            buttonTimerCallback
    );
    xTimerStart(xHeartbeatTimer, 0);    // 启动定时器 参数：定时器句柄，阻塞时间
}